//
//  GLESSprite.h
//  OpenGLES_03
//
//  Created by Keisuke Hata on 09/12/24.
//  Copyright 2009 Keisuke Hata. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

#import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/ES1/gl.h>

#import "GLESData.h"
#import "GLESPrim.h"
#import "DrawUtils.h"
#import "Texture2D.h"
#import "PVRTexture.h"
#import "TextureUtils.h"

// テクスチャフィルタリング
enum
{
	kEAGL_FILTER_NEAREST = 0, // 最近傍法
	kEAGL_FILTER_LINER  // 線形補間法
};

// テクスチャクランプ設定
enum
{
	kEAGL_WRAP_EDGE = 0, 
	kEAGL_WRAP_REPEAT
};

@interface EAGLSpriteBase : NSObject<EAGLDrawableDelegate> {
	
	BOOL _hidden;

}

- (void) calc;
- (void) draw;

@property (readwrite) BOOL hidden;

@end

@protocol EAGLTextureObjectDeleate

@optional
- (void) updatePositionX : (float)x;
- (void) updatePositionY : (float)y;
- (void) updateAnchorX : (float)x;
- (void) updateAnchorY : (float)y;
- (void) updateScale : (CGSize)scale;
- (void) updateAngleZ : (float)angleZ;

- (void) updateTextureFilter : (int)filter;
- (void) updateTextureWrap : (int)wrap;
- (void) updateTextureUV : (float)uv;
- (void) updateTextureUVOffset : (CGPoint)offs;

@end

@interface EAGLSprite2D : EAGLSpriteBase< EAGLTextureObjectDeleate >
{
	Texture2D	*_tex;
	CGPoint		_pos;
	CGPoint		_anchor;
	float		_alpha;
	float		_angleZ;
	CGSize		_scale;
	NSInteger	_magfilter;
	NSInteger	_minfilter;
	NSInteger   _blend_s;
	NSInteger   _blend_d;
	NSInteger	_wrap_s;
	NSInteger	_wrap_t;
	CGPoint		_offs;
	GLuint		_tag;
}

- (id) initWithFile : (NSString *)path;
- (id) initWithFile: (NSString *)path objTag:(GLuint)tag;

- (id) initWithPVRFile : (NSString *)path;
- (id) initWithPVRFile : (NSString *)path objTag:(GLuint)tag;

- (id) initWithTexture : (Texture2D *)tex;
- (id) initWithTexture : (Texture2D *)tex objTag:(GLuint)tag;

- (id) initWithText : (NSString *)text 
	   fontColor:(UIColor *)color
	   fontAlignment:(UITextAlignment)alignment 
	   fontName:(NSString *)name
	   fontSize:(CGFloat)size;

- (id) initWithText : (NSString *)text 
	   fontColor:(UIColor *)color
	   fontAlignment:(UITextAlignment)alignment 
	   fontName:(NSString *)name
	   fontSize:(CGFloat)size
	   objTag:(GLuint)tag;

- (void) setup;
- (void) draw;

@property (readwrite) CGPoint pos;
@property (readwrite) CGPoint anchor;
@property (readwrite) float alpha;
@property (readwrite) float angleZ;
@property (readwrite) CGSize scale;
@property (nonatomic,retain) Texture2D *texture;
@property (readwrite) GLuint tag;
@property (readonly) BOOL pvr;
@property (readonly) BOOL hasMipmap;

@end

@interface EAGLSprite3D : EAGLSpriteBase< EAGLTextureObjectDeleate >
{
	Texture2D	*_tex;
	GLVector3D	_vec;
	GLVector3D	_rot;
	GLVector3D	_anchor;
	
	float		_alpha;
	CGSize		_scale;
	NSInteger	_magfilter;
	NSInteger	_minfilter;
	NSInteger   _blend_s;
	NSInteger   _blend_d;
	NSInteger	_wrap_s;
	NSInteger	_wrap_t;
	CGPoint		_offs;
	GLuint		_tag;
}

- (id) initWithContentsOfFile : (NSString *)path;
- (id) initWithContentsOfFile: (NSString *)path objTag:(GLuint)tag;
- (id) initWithTexture : (Texture2D *)tex;
- (id) initWithTexture : (Texture2D *)tex objTag:(GLuint)tag;

- (void) draw;
- (void) setup;
- (void) destroy;

@property (readwrite) GLVector3D vec;
@property (readwrite) GLVector3D anchor;
@property (readwrite) GLVector3D rotate;

@property (readwrite) float alpha;
@property (readwrite) CGSize scale;
@property (nonatomic,retain) Texture2D *texture;
@property (readwrite) GLuint tag;
@property (readonly) BOOL pvr;
@property (readonly) BOOL hasMipmap;

@end
